package com.tanhua.server.controller;

import com.tanhua.model.dto.AnswersDto;
import com.tanhua.model.vo.SoulQuestionnaireVo;
import com.tanhua.model.vo.SoulResultVo;
import com.tanhua.server.service.TestSoulService;
import org.bouncycastle.asn1.cms.SCVPReqRes;
import org.bson.types.ObjectId;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/testSoul")
public class TestSoulController {

    @Autowired
    private TestSoulService testSoulService;

    /**
     * 测试灵魂问卷
     * @return
     */
    @GetMapping
    public ResponseEntity testSoul() {
        List<SoulQuestionnaireVo> vos = testSoulService.testSoul();
        return ResponseEntity.ok(vos);
    }
    /**
     * 提交问卷
     */
    @PostMapping
    public ResponseEntity submitSoul(@RequestBody Map<String,List<AnswersDto>> answers){
        List<AnswersDto> answersDtos = answers.get("answers");
        String result = testSoulService.submitSoul(answersDtos);
        return ResponseEntity.ok(result);
    }

    /**
     * 查看侧灵魂的的结果
     */
    @GetMapping("/report/{id}")
    public ResponseEntity findSurveyResults(@PathVariable("id") ObjectId id) {
        SoulResultVo<Object> map = testSoulService.findSurveyResults(id);
        return ResponseEntity.ok(map);
    }


}
